﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "教学运行管理 - 排课 - 学期教学任务");
		
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");

		termId = event.getArg("TID");
		depId = event.getArg("DepID");

		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		currentTab = event.getArg("TabID", "labDepartment");

		rs_ins = queryNew("institute_id");
		
		rs_planTask = queryNew("tsk_id");
		
		rs_commonTask = queryNew("tsk_id");
		
		rs_openTask = queryNew("tsk_id");

		rs_departmentEntity = queryNew("institute_id");

		targetArgs = structNew();

		if ( len(termId) ) {
			
			structInsert(targetArgs, "TID", termId);

			/* 如果有学期信息传递过来 */
			sql = "SELECT
						i.institute_id,i.institute_name,COUNT(DISTINCT c.cid) c_count
					FROM
						t_task_arrange ta INNER JOIN t_course c ON ta.cid = c.cid INNER JOIN t_institute i ON i.institute_id = c.institute_id
					WHERE
						ta.term_id = :termId 
					GROUP BY
						i.institute_id,i.institute_name
					ORDER BY
						i.institute_name";
			
			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
			rs_ins = queryObj.execute(sql = sql).getResult();

			if ( len(depId) ) {
				
				currentTab = "labTask";
				
				sql = "	SELECT
							i.institute_id,i.institute_name
						FROM
							t_institute i
						WHERE
							i.institute_id = :depID ";
				
				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name = "depID", value = depID, cfsqltype = "cf_sql_varchar");
				rs_departmentEntity = queryObj.execute(sql = sql).getResult();
			
				sql = "	SELECT
							a.tsk_id,ac.course_name,at.tch_name,a.cidx,a.task_week,
							a.task_limite,a.task_chooesd,act.cr_type_name,acu.campus_name,
							CASE WHEN a.task_time IS NULL THEN '-' ELSE a.task_time END task_time,
							CASE WHEN a.task_place IS NULL THEN '-' ELSE a.task_place END task_place,
							a.task_prop
						FROM
							t_task a INNER JOIN t_course ac ON ac.cid = a.cid INNER JOIN t_teacher at ON at.tch_id = a.tch_id 
							INNER JOIN t_classroom_type act ON act.cr_type = a.cr_type INNER JOIN t_campus acu ON acu.campus_id = a.campus_id
						WHERE
							a.term_id = :termId 
							AND
							ac.institute_id = :depId 
							AND
							EXISTS(
								SELECT 0 FROM t_task_arrange b WHERE b.task_id = a.tsk_id AND b.term_id = :termId 
							)
							AND
							   SUBSTR(a.task_prop,7,1) = '0'
						ORDER BY
							ac.course_name,a.cidx";
				
				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name = "depId", value = depID, cfsqltype = "cf_sql_varchar");
				queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
				rs_planTask = queryObj.execute(sql = sql).getResult();
				
				sql = "	SELECT
							a.tsk_id,ac.course_name,at.tch_name,a.cidx,a.task_week,
							a.task_limite,a.task_chooesd,act.cr_type_name,acu.campus_name,
							CASE WHEN a.task_time IS NULL THEN '-' ELSE a.task_time END task_time,
							CASE WHEN a.task_place IS NULL THEN '-' ELSE a.task_place END task_place,
							a.task_prop
						FROM
							t_common_task a INNER JOIN t_course ac ON ac.cid = a.cid INNER JOIN t_teacher at ON at.tch_id = a.tch_id 
							INNER JOIN t_classroom_type act ON act.cr_type = a.cr_type INNER JOIN t_campus acu ON acu.campus_id = a.campus_id
						WHERE
							a.term_id = :termId 
							AND
							ac.institute_id = :depId 
							AND
							EXISTS(
								SELECT 0 FROM t_task_arrange b WHERE b.task_id = a.tsk_id AND b.term_id = :termId 
							)
							AND
							   SUBSTR(a.task_prop,7,1) = '0'
						ORDER BY
							ac.course_name,a.cidx";
				
				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name = "depId", value = depID, cfsqltype = "cf_sql_varchar");
				queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
				rs_commonTask = queryObj.execute(sql = sql).getResult();

				sql = "	SELECT
							a.tsk_id,ac.course_name,at.tch_name,a.cidx,a.task_week,
							a.task_limite,a.task_chooesd,act.cr_type_name,acu.campus_name,
							CASE WHEN a.task_time IS NULL THEN '-' ELSE a.task_time END task_time,
							CASE WHEN a.task_place IS NULL THEN '-' ELSE a.task_place END task_place,
							a.task_prop
						FROM
							t_reopen_task a INNER JOIN t_course ac ON ac.cid = a.cid INNER JOIN t_teacher at ON at.tch_id = a.tch_id 
							INNER JOIN t_classroom_type act ON act.cr_type = a.cr_type INNER JOIN t_campus acu ON acu.campus_id = a.campus_id
						WHERE
							a.term_id = :termId 
							AND
							ac.institute_id = :depId 
							AND
							EXISTS(
								SELECT 0 FROM t_task_arrange b WHERE b.task_id = a.tsk_id AND b.term_id = :termId 
							)
							AND
							   SUBSTR(a.task_prop,7,1) = '0'
						ORDER BY
							ac.course_name,a.cidx";
				
				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name = "depId", value = depID, cfsqltype = "cf_sql_varchar");
				queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
				rs_openTask = queryObj.execute(sql = sql).getResult();

			}
		}
		

		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i>学期教学任务
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				
				<cfif termId eq "">
					<!-- termSelector -->
					<cfoutput>#event.getArg("termSelector")#</cfoutput>
					<!-- /termSelector -->
				</cfif>
				
				<cfif len(termId)>
				
					<div class="UItab">
						<div class="tabLables">
							<span <cfif currentTab eq "labDepartment">class="active"</cfif> id="labDepartment" tabTarget="Department">任课单位</span>
							<cfif len(depID)>
								<span <cfif currentTab eq "labTask">class="active"</cfif> id="labTask" tabTarget="Task">课程开设情况</span>
							</cfif>
						</div>
					</div>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
						
							/* init Tab */
							$("div.tabContent[@id!=' + $targetID + ']").hide();
							$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
							$("div.tabLables > span").click(function(){
								var $targetID = $(this).attr("tabTarget");
							
								$("div.tabLables span").removeClass("active");
								$(this).addClass("active");
							
								$("div.tabContent[@id!=' + $targetID + ']").hide();
								$("div.tabContent#" + $targetID).show();
							});
						
						});
						// -->
						//]]>
					</script>
					
					<div id="Department" class="tabContent">
					
						<div class="noticeBlock">
							<div class="operation">
								<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('taskDownloadExcel', targetArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载全校教学任务</span></a>
							</div>
							<h3>学期课程开课单位</h3>
							<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期教学任务共计 <em><cfoutput>#rs_ins.recordCount#</cfoutput></em> 个任课单位共同完成.</p>
							<hr/>
						</div>
					
						<div class="clearfix">
							<div class="UICardTable">
                                <cfloop query="rs_ins">
									<cfset structInsert(targetArgs, "DepID", rs_ins.institute_id, true) />
									<dl>
										<dt>
											<a href="<cfoutput>#buildURL('taskClass', targetArgs)#</cfoutput>">
											<em class="collection"><!--imgholder--></em>
											<dd>
												<h3><cfoutput>#rs_ins.institute_name#</cfoutput></h3>
												<div>承担 <cfoutput>#rs_ins.c_count#</cfoutput> 门课程</div>
											</dd>
											</a>
										</dt>
									</dl>
								</cfloop>
							</div>
						</div>
					
					</div>
					
					<div id="Task" class="tabContent">
						
						<cfif rs_departmentEntity.recordCount>
							
							<cfset structInsert(targetArgs, "DepID", rs_departmentEntity.institute_id, true) />
							
							<div class="noticeBlock">
								<div class="operation">
									<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('depTaskDownloadExcel', targetArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载学院教学任务</span></a>
								</div>
								<h3><cfoutput>#rs_departmentEntity.institute_name#</cfoutput></h3>
								<p>
									<span class="img icon16x16 message"></span>
									<em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期, 
									需承担计划课程教学任务 <em><cfoutput>#rs_planTask.recordCount#</cfoutput></em> 个,
									需承担全通通选课程教学任务 <em><cfoutput>#rs_commonTask.recordCount#</cfoutput></em> 个
									.
								</p>
								<hr/>
							</div>
						
						</cfif>
						
						<cfif rs_planTask.recordCount or rs_commonTask.recordCount or rs_openTask.recordCount>

							<table id="classList" class="UIEditable">
								<thead>
									<tr>
										<td width="30"></td>
										<td>教学班</td>
										<td>周次</td>
										<td>人数</td>
										<td>校区</td>
										<td>教室类别</td>
										<td>上课时间</td>
										<td>上课地点</td>
									</tr>
								</thead>
								<tbody>
									<cfset row = 0 />
                                    <cfloop query="rs_planTask">
										<cfset row++ />
										<tr class="editRows" rowid="<cfoutput>#rs_planTask.tsk_id#</cfoutput>">
											<td class="index">P.<cfoutput>#row#</cfoutput></td>
											<td><cfoutput>#rs_planTask.course_name#-#rs_planTask.tch_name#-<span class="numeric">#rs_planTask.cidx#</span></cfoutput></td>
											<td><span class="numeric"><cfoutput>#rs_planTask.task_week#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_planTask.task_chooesd# / #rs_planTask.task_limite#</cfoutput></span></td>
											<td><cfoutput>#rs_planTask.campus_name#</cfoutput></td>
											<td><cfoutput>#rs_planTask.cr_type_name#</cfoutput></td>
											<td><cfoutput>#replace(mathAdvice.convertTaskTime(rs_planTask.task_time), ",", "<br/>", "all")#</cfoutput></td>
											<td><cfoutput>#replace(rs_planTask.task_place, ",", "<br/>", "all")#</cfoutput></td>
										</tr>
									</cfloop>
									
									<cfset row = 0 />
                                    <cfloop query="rs_commonTask">
										<cfset row++ />
										<tr class="editRows" rowid="<cfoutput>#rs_commonTask.tsk_id#</cfoutput>">
											<td class="index">C.<cfoutput>#row#</cfoutput></td>
											<td><cfoutput>#rs_commonTask.course_name#-#rs_commonTask.tch_name#-<span class="numeric">#rs_commonTask.cidx#</span></cfoutput></td>
											<td><span class="numeric"><cfoutput>#rs_commonTask.task_week#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_commonTask.task_chooesd# / #rs_commonTask.task_limite#</cfoutput></span></td>
											<td><cfoutput>#rs_commonTask.campus_name#</cfoutput></td>
											<td><cfoutput>#rs_commonTask.cr_type_name#</cfoutput></td>
											<td><cfoutput>#replace(mathAdvice.convertTaskTime(rs_commonTask.task_time), ",", "<br/>", "all")#</cfoutput></td>
											<td><cfoutput>#replace(rs_commonTask.task_place, ",", "<br/>", "all")#</cfoutput></td>
										</tr>
									</cfloop>
									
									<cfset row = 0 />
                                    <cfloop query="rs_openTask">
										<cfset row++ />
										<tr class="editRows" rowid="<cfoutput>#rs_openTask.tsk_id#</cfoutput>">
											<td class="index">R.<cfoutput>#row#</cfoutput></td>
											<td><cfoutput>#rs_openTask.course_name#-#rs_openTask.tch_name#-<span class="numeric">#rs_openTask.cidx#</span></cfoutput></td>
											<td><span class="numeric"><cfoutput>#rs_openTask.task_week#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_openTask.task_chooesd# / #rs_openTask.task_limite#</cfoutput></span></td>
											<td><cfoutput>#rs_openTask.campus_name#</cfoutput></td>
											<td><cfoutput>#rs_openTask.cr_type_name#</cfoutput></td>
											<td><cfoutput>#replace(mathAdvice.convertTaskTime(rs_openTask.task_time), ",", "<br/>", "all")#</cfoutput></td>
											<td><cfoutput>#replace(rs_openTask.task_place, ",", "<br/>", "all")#</cfoutput></td>
										</tr>
									</cfloop>
									
								</tbody>
							</table>
						</cfif>
					</div>
					
				</cfif>
				
			</div>
		</li>
	</ul>
</div>